/*
 * To change this license header, choose License Headers in Project Properties.
 */

package dreamwar.model.POJO;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Berto_Romero
 */
@Entity
@Table(name = "feature")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Feature.findAll", query = "SELECT f FROM Feature f"),
    @NamedQuery(name = "Feature.findByIdFeature", query = "SELECT f FROM Feature f WHERE f.idFeature = :idFeature"),
    @NamedQuery(name = "Feature.findByFeatureName", query = "SELECT f FROM Feature f WHERE f.featureName = :featureName"),
    @NamedQuery(name = "Feature.findByCost", query = "SELECT f FROM Feature f WHERE f.cost = :cost"),
    @NamedQuery(name = "Feature.findByUnitFeature", query = "SELECT f FROM Feature f WHERE f.unitFeature = :unitFeature")})
public class Feature implements Serializable {
    @Transient
    private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id_feature")
    private Integer idFeature;
    @Column(name = "feature_name")
    private String featureName;
    @Lob
    @Column(name = "feature_description")
    private String featureDescription;
    @Column(name = "cost")
    private Integer cost;
    @Column(name = "unit_feature")
    private Boolean unitFeature;
    @JoinTable(name = "feature_weapon", joinColumns = {
        @JoinColumn(name = "id_feature", referencedColumnName = "id_feature")}, inverseJoinColumns = {
        @JoinColumn(name = "id_weapon", referencedColumnName = "id_weapon")})
    @ManyToMany
    private Collection<Weapon> weaponCollection;

    public Feature() {
    }

    public Feature(Integer idFeature) {
        this.idFeature = idFeature;
    }

    public Integer getIdFeature() {
        return idFeature;
    }

    public void setIdFeature(Integer idFeature) {
        Integer oldIdFeature = this.idFeature;
        this.idFeature = idFeature;
        changeSupport.firePropertyChange("idFeature", oldIdFeature, idFeature);
    }

    public String getFeatureName() {
        return featureName;
    }

    public void setFeatureName(String featureName) {
        String oldFeatureName = this.featureName;
        this.featureName = featureName;
        changeSupport.firePropertyChange("featureName", oldFeatureName, featureName);
    }

    public String getFeatureDescription() {
        return featureDescription;
    }

    public void setFeatureDescription(String featureDescription) {
        String oldFeatureDescription = this.featureDescription;
        this.featureDescription = featureDescription;
        changeSupport.firePropertyChange("featureDescription", oldFeatureDescription, featureDescription);
    }

    public Integer getCost() {
        return cost;
    }

    public void setCost(Integer cost) {
        Integer oldCost = this.cost;
        this.cost = cost;
        changeSupport.firePropertyChange("cost", oldCost, cost);
    }

    public Boolean getUnitFeature() {
        return unitFeature;
    }

    public void setUnitFeature(Boolean unitFeature) {
        Boolean oldUnitFeature = this.unitFeature;
        this.unitFeature = unitFeature;
        changeSupport.firePropertyChange("unitFeature", oldUnitFeature, unitFeature);
    }

    @XmlTransient
    public Collection<Weapon> getWeaponCollection() {
        return weaponCollection;
    }

    public void setWeaponCollection(Collection<Weapon> weaponCollection) {
        this.weaponCollection = weaponCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idFeature != null ? idFeature.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Feature)) {
            return false;
        }
        Feature other = (Feature) object;
        if ((this.idFeature == null && other.idFeature != null) || (this.idFeature != null && !this.idFeature.equals(other.idFeature))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "dreamwar.model.POJO.Feature[ idFeature=" + idFeature + " ]";
    }
    
    public void addPropertyChangeListener(PropertyChangeListener listener) {
            changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
